//
//  LYYBreakRuleViewController.m
//  Icar
//
//  Created by dllo on 15/10/23.
//  Copyright © 2015年 小龙侠. All rights reserved.
//

#import "LYYBreakRuleViewController.h"

@interface LYYBreakRuleViewController ()<UIWebViewDelegate>
{
     UIActivityIndicatorView *activity;
}
@end

@implementation LYYBreakRuleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;
    UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH(375), HEIGHT(64))];
    [titleView setBackgroundColor:BLUECOLOR];
    [self.view addSubview:titleView];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"iconfont-fanhui"] forState:UIControlStateNormal];
    [backButton setFrame:CGRectMake(WIDTH(2), HEIGHT(20), WIDTH(60), HEIGHT(40))];
    [backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [titleView addSubview:backButton];
    
    _webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    
    NSURLRequest * request = [[NSURLRequest alloc]initWithURL:[NSURL  URLWithString:@"http://mrobot.pcauto.com.cn/xsp/s/auto/info/v4.7/illegalQueryv47.xsp"]];

    [_webview  loadRequest:request];
    [self.view  addSubview:_webview];
    //创建小菊花
    activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activity.center =self.view.center;
    [self.view addSubview:activity];
    [self.view setBackgroundColor:[LYYNightModeHandle shareNightModeHandle].backColor];
    
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeClick :)];
    [swipe setDirection:UISwipeGestureRecognizerDirectionRight];
    [_webview addGestureRecognizer:swipe];
    _webview.delegate = self;
}

-(void)backButtonClick
{
#pragma mark- 返回指定页面
    UIViewController *vc =[self.navigationController.viewControllers objectAtIndex:0];
    [self.navigationController popToViewController:vc animated:YES];
}
#pragma mark-滑动手势
-(void)swipeClick:(UISwipeGestureRecognizer *)swipe
{
    UIViewController *vc =[self.navigationController.viewControllers objectAtIndex:0];
    [self.navigationController popToViewController:vc animated:YES];
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [activity startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    if ([LYYNightModeHandle shareNightModeHandle].temp == YES) {
        [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'gray'"];
        [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
    }
    [activity stopAnimating];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [activity stopAnimating];
}

- (void)viewWillAppear:(BOOL)animated{
    
    [self.webview reload];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
